package com.cloudkinto.controller.message;


import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.extentity.message.MessageNoticeDto;
import com.cloudkinto.service.product.vo.ProductOutExportReq;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cloudkinto.service.message.MessageNoticeService;

import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.cloudkinto.base.BaseController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hua
 * @since 2023-08-10
 */
@RestController
@Api(tags = "消息中心模块")
@RequestMapping("/api/admin/MessageNotice")
public class MessageNoticeController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(MessageNoticeController.class);

    @Autowired
    private MessageNoticeService service;

    @UserSessionRequired
    @GetMapping("/addInit")
    @ApiOperation(value = "新增初始化", notes = "新增初始化")
    public SingleResult addInit() {
        return service.addInit();
    }

//    @PostMapping("")
//    @ApiOperation(value = "新增", notes = "新增")
//    public SingleResult add(@RequestBody @Validated Object req) {
//        Long userId = getCurrentUserId();
//        Long companyId = getCompanyId();
//        return SingleResult.success("新增成功",service.add(req,userId));
//    }

//    @UserSessionRequired
//    @GetMapping("/updateInit/{id}")
//    @ApiOperation(value = "编辑初始化", notes = "编辑初始化")
//    public SingleResult updateInit(@PathVariable("id") Long id) {
//        return service.updateInit(id);
//    }

    @UserSessionRequired
    @GetMapping("/markDeal")
    @ApiOperation(value = "标记已处理", notes = "标记已处理")
    public SingleResult markDeal(Long id) {
        Long userId = getCurrentUserId();
        service.markDeal(id, userId);
        return SingleResult.success();
    }


    @UserSessionRequired
    @GetMapping("exportRackNotice")
    @ApiOperation(value = "导出异常库位")
    public void exportRackNotice(HttpServletRequest request, HttpServletResponse response) {
        Map<String, String> map = new HashMap<>();
        String keyword = request.getParameter("keyword");
        String status = request.getParameter("status");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");

        map.put("keyword", keyword);
        map.put("status", status);
        map.put("beginTime", beginTime);
        map.put("endTime", endTime);

        service.exportRackNotice(map, response);
    }



//    @GetMapping("/{id}")
//    @ApiOperation(value = "根据id查看详情", notes = "根据id查看详情")
//    public SingleResult detail(@PathVariable("id") Long id) {
//        return SingleResult.success("查询成功",service.detail(id));
//    }
//
    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "查询初始化", notes = "查询初始化")
    public SingleResult pageInit() {
        return service.pageInit();
    }

//    @GetMapping("/list")
//    @ApiOperation(value = "查询", notes = "查询")
//    public SingleResult list(HttpServletRequest request){
//        Long companyId = getCompanyId();
//
//        Map<String, String> map = new HashMap<>();
//        String keyword = request.getParameter("keyword");
//        map.put("keyword", keyword);
//        return SingleResult.success("查询成功", service.getList(map));
//    }

    @UserSessionRequired
    @GetMapping("/listPage")
    @ApiOperation(value = "查询（分页）", notes = "查询（分页）")
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "status", value = "状态"),
//            @ApiImplicitParam(name = "storageId", value = "仓库id"),
            @ApiImplicitParam(name = "keyword", value = "关键词"),
            @ApiImplicitParam(name = "beginTime", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", value = "结束时间"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小")})
    @ApiResponses(@ApiResponse(code = 200, message = "", response = MessageNoticeDto.class))
    public PageResult listPage(HttpServletRequest request) {

        Map<String, String> map = new HashMap<>();
        String keyword = request.getParameter("keyword");
        String status = request.getParameter("status");
        String beginTime = request.getParameter("beginTime");
        String endTime = request.getParameter("endTime");
//        String storageId = request.getParameter("storageId");


        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("keyword", keyword);
        map.put("status", status);
        map.put("beginTime", beginTime);
        map.put("endTime", endTime);
//        map.put("storageId", storageId);

        map.put("current", current);
        map.put("pageSize", size);
        return service.getListPage(map);
    }

}

